#property copyright "Copyright 2012"
#property link      "mingxinhe@gmail.com"

#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
#property indicator_width1 1

extern int period = 13;

double TimeSMABuffer[];
double TimeBuffer[];

int init()
{
      IndicatorBuffers(2);   
      SetIndexStyle(0,DRAW_LINE);
      SetIndexBuffer(0, TimeSMABuffer);
      SetIndexStyle(1,DRAW_NONE);
      SetIndexBuffer(1, TimeBuffer);
      IndicatorShortName("Time SMA("+period+")");
      IndicatorDigits(5);

      return(0);
}

int deinit()
{
//---- TODO: add your code here
// --------------------------
//----
   return(0);
}

int start()
{ 
      int  counted_bars=IndicatorCounted();        
      if(counted_bars>0) 
      {
         int limit=Bars-counted_bars + 1;
      }
      else
      {
         limit = Bars-1;
      }       

      for(int i=0; i<limit; i++)        
      {
          if (i == 0)
          {
              TimeBuffer[i] = TimeCurrent() - Time[i];              
          }
          else
          {
              TimeBuffer[i] = Time[i - 1] - Time[i];
          }
      } 
      
      for(i=0; i<limit; i++)        
      {
          TimeSMABuffer[i] = iMAOnArray(TimeBuffer,0,period,0,MODE_SMA,i);
      }          
      
      return(0);  
}